/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.senac.academicnet.view;

import br.com.senac.academicnet.model.AlunoBO;
import br.com.senac.academicnet.model.CursoBO;
import br.com.senac.academicnet.model.ProfessorBO;
import br.com.senac.academicnet.model.TurmaBO;
import br.com.senac.academicnet.model.entidades.AlunoVO;
import br.com.senac.academicnet.model.entidades.CursoVO;
import br.com.senac.academicnet.model.entidades.ProfessorVO;
import br.com.senac.academicnet.model.entidades.TurmaVO;
import br.com.senac.academicnet.view.aluno.AlunoTableModel;
import br.com.senac.academicnet.view.aluno.CadastroAluno;
import br.com.senac.academicnet.view.curso.CadastroCurso;
import br.com.senac.academicnet.view.curso.CursoTableModel;
import br.com.senac.academicnet.view.professor.CadastroProfessor;
import br.com.senac.academicnet.view.professor.ProfessorTableModel;
import br.com.senac.academicnet.view.turma.CadastroTurma;
import br.com.senac.academicnet.view.turma.TurmaTableModel;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

public class Principal extends javax.swing.JFrame {

    /**
	 * 
	 */
	private static final long serialVersionUID = -4556606083623703434L;

	/**
     * Creates new form Principal
     */
    public Principal() {
        initComponents(); 
        this.consultar();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fileChooser = new javax.swing.JFileChooser();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        panelAlunos = new javax.swing.JPanel();
        btnVisualizarAluno = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblAlunos = new javax.swing.JTable();
        btnIncluirAluno = new javax.swing.JButton();
        btnExportarAlunos = new javax.swing.JButton();
        btnExcluirAlunos = new javax.swing.JButton();
        panelProfessores = new javax.swing.JPanel();
        btnVisualizarProfessor = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblProfessores = new javax.swing.JTable();
        btnIncluirProfessor = new javax.swing.JButton();
        btnExportarProfessores = new javax.swing.JButton();
        btnExcluirProfessores = new javax.swing.JButton();
        panelCursos = new javax.swing.JPanel();
        btnVisualizarCurso = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblCursos = new javax.swing.JTable();
        btnIncluirCurso = new javax.swing.JButton();
        btnExportarCursos = new javax.swing.JButton();
        btnExcluirCursos = new javax.swing.JButton();
        panelTurmas = new javax.swing.JPanel();
        btnVisualizarTurma = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        tblTurmas = new javax.swing.JTable();
        btnIncluirTurma = new javax.swing.JButton();
        btnExportarTurmas = new javax.swing.JButton();
        btnExcluirTurmas = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Academic Net");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        btnVisualizarAluno.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnVisualizarAluno.setText("Visualizar");
        btnVisualizarAluno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVisualizarAlunoActionPerformed(evt);
            }
        });

        tblAlunos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblAlunos.setName("tblAlunos"); // NOI18N
        jScrollPane1.setViewportView(tblAlunos);

        btnIncluirAluno.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnIncluirAluno.setText("Incluir");
        btnIncluirAluno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIncluirAlunoActionPerformed(evt);
            }
        });

        btnExportarAlunos.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnExportarAlunos.setText("Exportar CSV");
        btnExportarAlunos.setName("btnExportarAlunos"); // NOI18N
        btnExportarAlunos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExportarAlunosActionPerformed(evt);
            }
        });

        btnExcluirAlunos.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnExcluirAlunos.setText("Excluir Tudo");
        btnExcluirAlunos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirAlunosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelAlunosLayout = new javax.swing.GroupLayout(panelAlunos);
        panelAlunos.setLayout(panelAlunosLayout);
        panelAlunosLayout.setHorizontalGroup(
            panelAlunosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
            .addGroup(panelAlunosLayout.createSequentialGroup()
                .addComponent(btnIncluirAluno)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnVisualizarAluno)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExportarAlunos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExcluirAlunos)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        panelAlunosLayout.setVerticalGroup(
            panelAlunosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAlunosLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelAlunosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnIncluirAluno)
                    .addComponent(btnVisualizarAluno)
                    .addComponent(btnExportarAlunos)
                    .addComponent(btnExcluirAlunos)))
        );

        jTabbedPane1.addTab("Alunos", panelAlunos);

        btnVisualizarProfessor.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnVisualizarProfessor.setText("Visualizar");
        btnVisualizarProfessor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVisualizarProfessorActionPerformed(evt);
            }
        });

        tblProfessores.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblProfessores.setName("tblProfessores"); // NOI18N
        jScrollPane2.setViewportView(tblProfessores);

        btnIncluirProfessor.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnIncluirProfessor.setText("Incluir");
        btnIncluirProfessor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIncluirProfessorActionPerformed(evt);
            }
        });

        btnExportarProfessores.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnExportarProfessores.setText("Exportar CSV");
        btnExportarProfessores.setName("btnExportar"); // NOI18N
        btnExportarProfessores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExportarProfessoresActionPerformed(evt);
            }
        });

        btnExcluirProfessores.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnExcluirProfessores.setText("Excluir Tudo");
        btnExcluirProfessores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirProfessoresActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelProfessoresLayout = new javax.swing.GroupLayout(panelProfessores);
        panelProfessores.setLayout(panelProfessoresLayout);
        panelProfessoresLayout.setHorizontalGroup(
            panelProfessoresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelProfessoresLayout.createSequentialGroup()
                .addComponent(btnIncluirProfessor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnVisualizarProfessor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExportarProfessores)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExcluirProfessores)
                .addContainerGap(262, Short.MAX_VALUE))
            .addGroup(panelProfessoresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE))
        );
        panelProfessoresLayout.setVerticalGroup(
            panelProfessoresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelProfessoresLayout.createSequentialGroup()
                .addGap(0, 297, Short.MAX_VALUE)
                .addGroup(panelProfessoresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnIncluirProfessor)
                    .addComponent(btnVisualizarProfessor)
                    .addComponent(btnExportarProfessores)
                    .addComponent(btnExcluirProfessores)))
            .addGroup(panelProfessoresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelProfessoresLayout.createSequentialGroup()
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 25, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab("Professores", panelProfessores);

        btnVisualizarCurso.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnVisualizarCurso.setText("Visualizar");
        btnVisualizarCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVisualizarCursoActionPerformed(evt);
            }
        });

        tblCursos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblCursos.setName("tblAlunos"); // NOI18N
        jScrollPane3.setViewportView(tblCursos);

        btnIncluirCurso.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnIncluirCurso.setText("Incluir");
        btnIncluirCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIncluirCursoActionPerformed(evt);
            }
        });

        btnExportarCursos.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnExportarCursos.setText("Exportar CSV");
        btnExportarCursos.setName("btnExportar"); // NOI18N
        btnExportarCursos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExportarCursosActionPerformed(evt);
            }
        });

        btnExcluirCursos.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnExcluirCursos.setText("Excluir Tudo");
        btnExcluirCursos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirCursosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelCursosLayout = new javax.swing.GroupLayout(panelCursos);
        panelCursos.setLayout(panelCursosLayout);
        panelCursosLayout.setHorizontalGroup(
            panelCursosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
            .addGroup(panelCursosLayout.createSequentialGroup()
                .addComponent(btnIncluirCurso)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnVisualizarCurso)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExportarCursos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExcluirCursos)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        panelCursosLayout.setVerticalGroup(
            panelCursosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCursosLayout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelCursosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnIncluirCurso)
                    .addComponent(btnVisualizarCurso)
                    .addComponent(btnExportarCursos)
                    .addComponent(btnExcluirCursos)))
        );

        jTabbedPane1.addTab("Cursos", panelCursos);

        btnVisualizarTurma.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnVisualizarTurma.setText("Visualizar");
        btnVisualizarTurma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVisualizarTurmaActionPerformed(evt);
            }
        });

        tblTurmas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblTurmas.setName("tblAlunos"); // NOI18N
        jScrollPane4.setViewportView(tblTurmas);

        btnIncluirTurma.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnIncluirTurma.setText("Incluir");
        btnIncluirTurma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIncluirTurmaActionPerformed(evt);
            }
        });

        btnExportarTurmas.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnExportarTurmas.setText("Exportar CSV");
        btnExportarTurmas.setName("btnExportarAlunos"); // NOI18N
        btnExportarTurmas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExportarTurmasActionPerformed(evt);
            }
        });

        btnExcluirTurmas.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        btnExcluirTurmas.setText("Excluir Tudo");
        btnExcluirTurmas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirTurmasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelTurmasLayout = new javax.swing.GroupLayout(panelTurmas);
        panelTurmas.setLayout(panelTurmasLayout);
        panelTurmasLayout.setHorizontalGroup(
            panelTurmasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
            .addGroup(panelTurmasLayout.createSequentialGroup()
                .addComponent(btnIncluirTurma)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnVisualizarTurma)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExportarTurmas)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExcluirTurmas)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        panelTurmasLayout.setVerticalGroup(
            panelTurmasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTurmasLayout.createSequentialGroup()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelTurmasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnIncluirTurma)
                    .addComponent(btnVisualizarTurma)
                    .addComponent(btnExportarTurmas)
                    .addComponent(btnExcluirTurmas)))
        );

        jTabbedPane1.addTab("Turmas", panelTurmas);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("ACADEMIC NET - Victor Hugo e Pedro Albani");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
            .addGroup(layout.createSequentialGroup()
                .addGap(119, 119, 119)
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 348, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnVisualizarAlunoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVisualizarAlunoActionPerformed
        visualizarAluno();
    }//GEN-LAST:event_btnVisualizarAlunoActionPerformed

    private void btnIncluirAlunoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncluirAlunoActionPerformed
        incluirAluno();
    }//GEN-LAST:event_btnIncluirAlunoActionPerformed

    private void btnExportarAlunosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarAlunosActionPerformed
        exportarAluno();
    }//GEN-LAST:event_btnExportarAlunosActionPerformed

    private void btnExcluirAlunosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirAlunosActionPerformed
        excluirTudoAluno();
    }//GEN-LAST:event_btnExcluirAlunosActionPerformed

    private void btnVisualizarProfessorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVisualizarProfessorActionPerformed
        visualizarProfessor();
    }//GEN-LAST:event_btnVisualizarProfessorActionPerformed

    private void btnIncluirProfessorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncluirProfessorActionPerformed
        incluirProfessor();
    }//GEN-LAST:event_btnIncluirProfessorActionPerformed

    private void btnExportarProfessoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarProfessoresActionPerformed
        exportarProfessor();
    }//GEN-LAST:event_btnExportarProfessoresActionPerformed

    private void btnExcluirProfessoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirProfessoresActionPerformed
        excluirTudoProfessor();
    }//GEN-LAST:event_btnExcluirProfessoresActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        consultar();
    }//GEN-LAST:event_formWindowActivated

    private void btnVisualizarCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVisualizarCursoActionPerformed
        visualizarCurso();
    }//GEN-LAST:event_btnVisualizarCursoActionPerformed

    private void btnIncluirCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncluirCursoActionPerformed
        incluirCurso();
    }//GEN-LAST:event_btnIncluirCursoActionPerformed

    private void btnExportarCursosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarCursosActionPerformed
        exportarCurso();
    }//GEN-LAST:event_btnExportarCursosActionPerformed

    private void btnExcluirCursosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirCursosActionPerformed
        excluirTudoCurso();
    }//GEN-LAST:event_btnExcluirCursosActionPerformed

    private void btnVisualizarTurmaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVisualizarTurmaActionPerformed
        visualizarTurma();
    }//GEN-LAST:event_btnVisualizarTurmaActionPerformed

    private void btnIncluirTurmaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncluirTurmaActionPerformed
        incluirTurma();
    }//GEN-LAST:event_btnIncluirTurmaActionPerformed

    private void btnExportarTurmasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportarTurmasActionPerformed
        exportarTurma();
    }//GEN-LAST:event_btnExportarTurmasActionPerformed

    private void btnExcluirTurmasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirTurmasActionPerformed
        excluirTudoTurma();
    }//GEN-LAST:event_btnExcluirTurmasActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnExcluirAlunos;
    private javax.swing.JButton btnExcluirCursos;
    private javax.swing.JButton btnExcluirProfessores;
    private javax.swing.JButton btnExcluirTurmas;
    private javax.swing.JButton btnExportarAlunos;
    private javax.swing.JButton btnExportarCursos;
    private javax.swing.JButton btnExportarProfessores;
    private javax.swing.JButton btnExportarTurmas;
    private javax.swing.JButton btnIncluirAluno;
    private javax.swing.JButton btnIncluirCurso;
    private javax.swing.JButton btnIncluirProfessor;
    private javax.swing.JButton btnIncluirTurma;
    private javax.swing.JButton btnVisualizarAluno;
    private javax.swing.JButton btnVisualizarCurso;
    private javax.swing.JButton btnVisualizarProfessor;
    private javax.swing.JButton btnVisualizarTurma;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel panelAlunos;
    private javax.swing.JPanel panelCursos;
    private javax.swing.JPanel panelProfessores;
    private javax.swing.JPanel panelTurmas;
    private javax.swing.JTable tblAlunos;
    private javax.swing.JTable tblCursos;
    private javax.swing.JTable tblProfessores;
    private javax.swing.JTable tblTurmas;
    // End of variables declaration//GEN-END:variables
    
    List<AlunoVO> alunos = new ArrayList<>();
    AlunoTableModel modelAluno = new AlunoTableModel(alunos);
    
    List<ProfessorVO> professores = new ArrayList<>();
    ProfessorTableModel modelProfessor = new ProfessorTableModel(professores);
    
    List<CursoVO> cursos = new ArrayList<>();
    CursoTableModel modelCurso = new CursoTableModel(cursos);
    
    List<TurmaVO> turmas = new ArrayList<>();
    TurmaTableModel modelTurma = new TurmaTableModel(turmas);

    private void consultar() {
        try {
            professores = ProfessorBO.getProfessores();
            modelProfessor = new ProfessorTableModel(professores);
            tblProfessores.setModel(modelProfessor);
            
            alunos = AlunoBO.getAlunos();
            modelAluno = new AlunoTableModel(alunos);
            tblAlunos.setModel(modelAluno);
            
            cursos = CursoBO.getCursos();
            modelCurso = new CursoTableModel(cursos);
            tblCursos.setModel(modelCurso);
            
            turmas = TurmaBO.getTurmas();
            modelTurma = new TurmaTableModel(turmas);
            tblTurmas.setModel(modelTurma);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Erro ao consultar: " + ex.getMessage());
        }
    }

    private void incluirAluno() {
        CadastroAluno cadastroAluno = new CadastroAluno();
        cadastroAluno.setVisible(true);
    }

    private void visualizarAluno() {
        int row = tblAlunos.getSelectedRow();
        if (row >= 0) {
            CadastroAluno cadastroAluno = new CadastroAluno(modelAluno.get(row));
            cadastroAluno.setVisible(true);
        }
    }
    
    private void excluirTudoAluno() {
        if (JOptionPane.showConfirmDialog(this, "Confirma exclusao de todos os alunos?") == 0) {
            try {
                AlunoBO.deletarTudo();
                //aluno.deletar(aluno.getCodigo());
                JOptionPane.showMessageDialog(this, "Registros excluidos!");
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "Erro ao excluir: " + ex.getMessage());
            }
        }
    }

    private void exportarAluno() {
        try {
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Arquivo CSV","csv");  
            fileChooser.setFileFilter(filter);
            int retorno = fileChooser.showOpenDialog(this);
            String arquivo = fileChooser.getSelectedFile().getAbsolutePath() + ".csv";
            
            if (retorno == JFileChooser.APPROVE_OPTION) {
                AlunoBO.exportarCSV(arquivo);
            }
            
            JOptionPane.showMessageDialog(this, "Arquivo gerado com sucesso!\n" 
                    + arquivo);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Falha ao escrever arquivo:\n" + e.getMessage());
        }
    }
    

    private void incluirProfessor() {
        CadastroProfessor cadastroProfessor = new CadastroProfessor();
        cadastroProfessor.setVisible(true);
    }

    private void visualizarProfessor() {
        int row = tblProfessores.getSelectedRow();
        if (row >= 0) {
            CadastroProfessor cadastroProfessor = new CadastroProfessor(modelProfessor.get(row));
            cadastroProfessor.setVisible(true);
        }
    }
    
    private void excluirTudoProfessor() {
        if (JOptionPane.showConfirmDialog(this, "Confirma exclusao de todos os professores?") == 0) {
            try {
                ProfessorBO.deletarTudo();
                JOptionPane.showMessageDialog(this, "Registros excluidos!");
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "Erro ao excluir: " + ex.getMessage());
            }
        }
    }

    private void exportarProfessor() {
        try {
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Arquivo CSV","csv");  
            fileChooser.setFileFilter(filter);
            int retorno = fileChooser.showOpenDialog(this);
            String arquivo = fileChooser.getSelectedFile().getAbsolutePath() + ".csv";
            
            if (retorno == JFileChooser.APPROVE_OPTION) {
                ProfessorBO.exportarCSV(arquivo);
            }
            
            JOptionPane.showMessageDialog(this, "Arquivo gerado com sucesso!\n" 
                    + arquivo);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Falha ao escrever arquivo:\n" + e.getMessage());
        }
    }

    
    private void incluirCurso() {
        CadastroCurso cadastroCurso = new CadastroCurso();
        cadastroCurso.setVisible(true);
    }

    private void visualizarCurso() {
        int row = tblCursos.getSelectedRow();
        if (row >= 0) {
            CadastroCurso cadastroCurso = new CadastroCurso(modelCurso.get(row));
            cadastroCurso.setVisible(true);
        }
    }
    
    private void excluirTudoCurso() {
        if (JOptionPane.showConfirmDialog(this, "Confirma exclusao de todos os cursos?") == 0) {
            try {
                CursoBO.deletarTudo();
                
                JOptionPane.showMessageDialog(this, "Registros excluidos!");
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "Erro ao excluir: " + ex.getMessage());
            }
        }
    }

    private void exportarCurso() {
        try {
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Arquivo CSV","csv");  
            fileChooser.setFileFilter(filter);
            int retorno = fileChooser.showOpenDialog(this);
            String arquivo = fileChooser.getSelectedFile().getAbsolutePath() + ".csv";
            
            if (retorno == JFileChooser.APPROVE_OPTION) {
                CursoBO.exportarCSV(arquivo);
            }
            
            JOptionPane.showMessageDialog(this, "Arquivo gerado com sucesso!\n" 
                    + arquivo);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Falha ao escrever arquivo:\n" + e.getMessage());
        }
    }
    
     private void incluirTurma() {
        CadastroTurma cadastroTurma = new CadastroTurma();
        cadastroTurma.setVisible(true);
    }

    private void visualizarTurma() {
        int row = tblTurmas.getSelectedRow();
        if (row >= 0) {
            CadastroTurma cadastroTurma = new CadastroTurma(modelTurma.get(row));
            cadastroTurma.setVisible(true);
        }
    }
    
    private void excluirTudoTurma() {
        if (JOptionPane.showConfirmDialog(this, "Confirma exclusao de todos os cursos?") == 0) {
            try {
                TurmaBO.deletarTudo();
                
                JOptionPane.showMessageDialog(this, "Registros excluidos!");
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "Erro ao excluir: " + ex.getMessage());
            }
        }
    }

    private void exportarTurma() {
        try {
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Arquivo CSV","csv");  
            fileChooser.setFileFilter(filter);
            int retorno = fileChooser.showOpenDialog(this);
            String arquivo = fileChooser.getSelectedFile().getAbsolutePath() + ".csv";
            
            if (retorno == JFileChooser.APPROVE_OPTION) {
                TurmaBO.exportarCSV(arquivo);
            }
            
            JOptionPane.showMessageDialog(this, "Arquivo gerado com sucesso!\n" 
                    + arquivo);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Falha ao escrever arquivo:\n" + e.getMessage());
        }
    }
}
